package wordcloudtag;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import dataextraction.AbstractEntriesExporter;
import dataextraction.Entry;

public class WordCloudTagTXTExporter {

	private static WordCloudTagTXTExporter instance;

	private WordCloudTagTXTExporter() {

	}

	public static WordCloudTagTXTExporter getInstance() {
		if (WordCloudTagTXTExporter.instance == null) {
			WordCloudTagTXTExporter.instance = new WordCloudTagTXTExporter();
		}
		return WordCloudTagTXTExporter.instance;
	}

	public void exporter(Map<String, WordCloudTag> mapWordCloudTag , String file_path) throws IOException{

		StringBuffer content = new StringBuffer(); 

		List<WordCloudTag> listWordCloudTags = new ArrayList<WordCloudTag>(mapWordCloudTag.values());
		Collections.sort(listWordCloudTags);

		for(WordCloudTag wordCloudTag : listWordCloudTags){
			content.append(wordCloudTag.getWord()+" \t "+ wordCloudTag.getQuantity()+"\n");
		}

		FileWriter fw = new FileWriter(file_path,false);
		fw.write(content.toString());              
		fw.close(); 
	}
}
